[Solved] Problem getting Batch Files to run as Admin in Win 8.1

I'm trying to control certain Services with batch files to have them stop automatically at start.  However, with certain services, stopping requires run as admin.  My user account has admin privileges.

For example, a batch file with this command will stop with a command prompt requiring Y/N to confirm the stop.

NET STOP "Audiosrv"

I can create a shortcut and set it to run as admin and it will stop the service without issue when it's clicked.  However, if I put the shortcut in the Windows startup folder, so the script runs automatically at boot it seems to ignore the shortcuts.

I've tried the RunAs command below in a batch file, but it doesn't stop the service.

runas /user:jaguar\Admin NET STOP "Audiosrv"

Thanks for your help.



February 28th, 2014 10:15am

Did you try the runas command with the batchfile, not within the batchfile?

I've tried it with a batch named test.bat. The only content was

net stop audiosrv

pause

pause was only to see, if it works

Free Windows Admin Tool Kit Click here and download it now
February 28th, 2014 10:49am

It's Windows 8.1 - why don't give powershell a try:

stop-service audiosrv

Something like this

powershell.exe "Start-Process powershell -ArgumentList 'stop-service audiosrv' -Verb RunAs"

  • Edited by Peter Ziganki Friday, February 28, 2014 11:00 AM
  • Proposed as answer by Peter Ziganki Friday, February 28, 2014 11:35 AM
  • Marked as answer by forkenbrock 15 hours 37 minutes ago
February 28th, 2014 11:25am

Hello Peter, that works great.   I found I can add multiple arguments by separating them with a semi colon and I could hide the powershell window with the command at the end.

My last question is if there's an additional command that will hide or minimize the command line window when the script runs?

powershell.exe "Start-Process powershell -ArgumentList 'stop-service audiosrv; stop-service AudioEndpointBuilder; stop-service MMCSS' -Verb RunAs" -windowstyle hidden

Free Windows Admin Tool Kit Click here and download it now
March 3rd, 2014 12:26pm

Update: it appears that if you add the command "start /min" before powershell.exe, then the command window will just flash briefly and not remain on the screen until the script finishes running.
March 3rd, 2014 3:09pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics